<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"
    />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script src="./js/lib.js"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        .bg-disable{
            background: #ccc;
        }
    </style>
</head>

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="">web 内容管理</a>
            <a href="">经销商管理</a>
            <a>
                <cite>经销商详情</cite>
            </a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);"
            title="刷新">
            <i class="layui-icon" style="line-height:30px">ဂ</i>
        </a>
    </div>
    <div class="x-body">
        <div class="layui-form layui-form-pane">
            <div class="layui-form-item">
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>经销商-简体
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="agtNameCn" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>经销商-繁体
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="agtNameTw" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>经销商-英文
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="agtNameEn" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>联系方式
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="agtPhone" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>营业时间
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="openTime" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>经销商编码（例如A021）
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="agtCode" required lay-verify="required" autocomplete="off" class="layui-input bg-disable" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>地址-简体
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="addrCn" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>地址-繁体
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="addrTw" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>地址-英文
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="addrEn" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>坐标lat(谷歌）
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="lat" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>坐标lng
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="lng" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>状态(0：停用 1：启用)
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="status" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="" class="layui-form-label">简介-简体</label>
                <div class="layui-input-block">
                    <textarea name="descCn" placeholder="请输入内容" class="layui-textarea" required lay-verify="required"></textarea>
                </div>
                <label for="" class="layui-form-label">简介-繁体</label>
                <div class="layui-input-block">
                    <textarea name="descTw" placeholder="请输入内容" class="layui-textarea" required lay-verify="required"></textarea>
                </div>
                <label for="" class="layui-form-label">简介-英文</label>
                <div class="layui-input-block">
                    <textarea name="descEn" placeholder="请输入内容" class="layui-textarea" required lay-verify="required"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-dange" id="delete">
                    删除信息
                </button>
                <button  lay-submit lay-filter="modify" class="layui-btn layui-btn-warm">
                    确认修改
                </button>
            </div>
        </div>
    </div>

    <script>
        var aId = Cookies.get('kplus-helmetAdminId');
        var aToken = Cookies.get('kplus-helmetAdminToken');
        
        layui.use(['layer', 'form'], function (event) {
            var layer = layui.layer;
            var form = layui.form;
            //修改经销商信息
            function modifyAgt(param) { 
                var loadindex3 = layer.load(1, {
                    shade: [0.5, '#000']
                });
                $.ajax({
                    url: bAsEuRl + uRlS.agent,
                    type: 'post',
                    data: param,
                    success: function (data) {
                        if (data.msg.code == 200) {
                            layer.close(loadindex3);
                            layer.msg(data.data.msg, { time: 2000 });
                            location.reload();
                        } else {
                            layer.msg(data.msg.msg, { time: 2000 })
                            layer.close(loadindex3);
                        }
                    },
                    error: function () { 
                        layer.msg('系统发生严重错误，请联系维护人员', { time: 2000 })
                        layer.close(loadindex3);
                     }
                })
            }
            //获取经销商信息
            function getAgtInfo() {
                var loadindex1 = layer.load(1, {
                    shade: [0.5, '#000']
                });
                $.ajax({
                    url: bAsEuRl + uRlS.agent,
                    type: 'get',
                    data: {
                        'code': getParam('agt_code')
                    },
                    success: function (data) {
                        if (data.msg.code == 200) {
                            //console.log(data.data)
                            var agts = data.data[0];
                            $('input[name="agtNameCn"]').val(agts.agt_name.cn);
                            $('input[name="agtNameTw"]').val(agts.agt_name.tw);
                            $('input[name="agtNameEn"]').val(agts.agt_name.en);
                            $('input[name="agtPhone"]').val(agts.agt_phone);
                            $('input[name="openTime"]').val(agts.agt_open_daily);
                            $('input[name="addrCn"]').val(agts.agt_addr.cn);
                            $('input[name="addrTw"]').val(agts.agt_addr.tw);
                            $('input[name="addrEn"]').val(agts.agt_addr.en);
                            $('input[name="agtCode"]').val(agts.agt_code);
                            $('input[name="lat"]').val(agts.agt_coordinates[0]);
                            $('input[name="lng"]').val(agts.agt_coordinates[1]);
                            $('input[name="status"]').val(agts.agt_status);
                            $('textarea[name="descCn"]').val(agts.agt_intro.cn);
                            $('textarea[name="descTw"]').val(agts.agt_intro.tw);
                            $('textarea[name="descEn"]').val(agts.agt_intro.en);
                            layer.close(loadindex1)
                        } else {
                            layer.close(loadindex1);
                            layer.msg(data.msg.msg, { time: 2000 });
                        }
                    },
                    error: function (data) {
                        layer.close(loadindex1);
                        layer.msg(data.msg.msg, { time: 2000 });
                    }
                })
            }
            //新增传递
            function deleteAgt() {
                var loadindex2 = layer.load(1, {
                    shade: [0.5, '#000']
                });
                $.ajax({
                    url: bAsEuRl + uRlS.agent,
                    type: 'delete',
                    data: {
                        'aId': aId,
                        'aToken': aToken,
                        'code': getParam('agt_code')
                    },
                    success: function (data) {
                        if (data.msg.code == 200) {
                            layer.close(loadindex2);
                            layer.msg(data.data.msg, { time: 2000 });
                            window.parent.location.reload();
                            parent.layer.close(layer.index);
                        } else {
                            layer.close(loadindex2);
                            layer.msg(data.msg.msg, { time: 2000 });
                        }
                    },
                    error: function (data) {
                        layer.close(loadindex2);
                        layer.msg('系统发生严重错误，请联系维护人员')
                    }
                })
            }
            getAgtInfo()

            $('#delete').on('click', function(event) {
                layer.confirm('确定删除该经销商信息（不可恢复）？', {
                    btn: ['确定', '取消']
                }, function () {
                    deleteAgt()
                })
            });
            form.on('submit(modify)', function (data) {
                var agtData = {
                    'aId': aId,
                    'aToken': aToken,
                    'code': getParam('agt_code'),
                    'addr': 'cn:' + data.field.addrCn + '|tw:' + data.field.addrTw + '|en:' + data.field.addrEn,
                    'name': 'cn:' + data.field.agtNameCn + '|tw:' + data.field.agtNameTw + '|en:' + data.field.agtNameEn,
                    'phone': data.field.agtPhone,
                    'time': data.field.openTime,
                    'status': data.field.status,
                    'intro': 'cn:' + data.field.descCn + '|tw:' + data.field.descTw + '|en:' + data.field.descEn,
                    'coordinates': data.field.lat + "|" + data.field.lng
                }
                layer.confirm('确定修改该经销商信息？', {
                    btn: ['确定', '取消']
                }, function () {
                   modifyAgt(agtData)
                })
                return false;
            })
        })

    </script>
</body>

</html>